<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
		<title>学生管理</title>
		<link rel="stylesheet" href="res/layui/css/layui.css">
	</head>
	<body>
		<div style="text-align: center; margin-top: 200px;">
			<div class="layui-inline">
				<form class="layui-form" action="/">
					<div class="layui-form-item">
						<label class="layui-form-label">用户名</label>
						<div class="layui-input-inline">
							<input type="text" name="username" required lay-verify="required" autocomplete="off" class="layui-input">
						</div>
						<!-- <div class="layui-form-mid layui-word-aux">辅助文字</div> -->
					</div>
					<div class="layui-form-item">
						<label class="layui-form-label">密码</label>
						<div class="layui-input-inline">
							<input type="password" name="password" required lay-verify="required" placeholder="请输入密码" autocomplete="off"
							 class="layui-input">
						</div>
						<!-- <div class="layui-form-mid layui-word-aux">辅助文字</div> -->
					</div>
					<div class="layui-form-item">
						<div class="layui-input-block">
							<button class="layui-btn" lay-submit lay-filter="formDemo">提交</button>
							<button type="reset" class="layui-btn layui-btn-primary">重置</button>
						</div>
					</div>
				</form>
			</div>
		</div>

		<script src="res/jquery/jquery.min.js"></script>
		<script src="res/layui/layui.js"></script>
		<script src="res/js/public.js"></script>
		<script src="res/js/ajax-hook.js"></script>
		<script>
			//JavaScript代码区域
			layui.use(['form', 'layer'], function() {
				var form = layui.form,
					layer = layui.layer;

				//表单提交按钮
				form.on('submit(formDemo)', function(data) {
					// console.log(data.elem) //被执行事件的元素DOM对象，一般为button对象
					// console.log(data.form) //被执行提交的form对象，一般在存在form标签时才会返回
					// console.log(data.field) //当前容器的全部表单字段，名值对形式：{name: value}
					sendAjax('/api/login', 'POST', data.field, function(result) {
						//console.log(result);
						layer.msg('登录成功！', {
							icon: 1,
							time: 1500 //2秒关闭（如果不配置，默认是3秒）
						}, function() {
							sessionStorage.setItem('manageLogin', JSON.stringify(result.data));
							window.top.location.href = '/'; //应该使用重定向的，避免登录成功跳转后又跑回来登录
						});
					});
					
					return false; //阻止表单跳转。如果需要表单跳转，去掉这段即可。
				});
			});
		</script>
	</body>
</html>
